﻿@model MvcAtletIS.Models.Performances

@{
    ViewBag.Title = "Prihlásenie";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Prihlásenie</h2>

<div class="error">
    @ViewBag.Status
</div>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Prihlasovací formulár</legend>

        <div class="editor-label">
            Preteky
        </div>
        <div class="editor-field">
            @Html.DropDownList("CompetitionId", "Vyberte preteky")
        </div>
        
        <div class="editor-label">
            Disciplína
        </div>
        <div class="editor-field">
            @Html.DropDownList("DisciplineListId", "Vyberte disciplínu")
            @Html.ValidationMessageFor(model => model.DisciplineListId)
        </div>

        <div class="editor-label">
            Klub
        </div>
        <div class="editor-field">
            @Html.DropDownList("ClubId", "Vyberte klub")
        </div>

        <div class="editor-label">
            Pretekár
        </div>
        <div class="editor-field">
            @Html.ListBox("CompetitorId", null, new { @style = "width: 400px; height: 400px; " })
            @Html.ValidationMessageFor(model => model.CompetitorId)
        </div>

        <p>
            <input type="submit" value="Prihlásiť" />
        </p>

    </fieldset>
}

<div>
    @Html.ActionLink("Naspäť na editor prihlášok", "Index")
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $("#CompetitionId").change(function () {
            var idCompetition = $(this).val();
            $.getJSON("/Signups/LoadDisciplinesForCompetition", { id: idCompetition },
            function (competitorsData) {
                var select = $("#DisciplineListId");
                select.empty();
                select.append($('<option/>',
                {
                    value: null,
                    text: "Vyberte disciplínu"
                }));
                $.each(competitorsData, function (index, itemData) {
                    select.append($('<option/>',
                    {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });
    });
</script>

<script type="text/javascript">
    $(document).ready(function () {
        $("#ClubId").change(function () {
            var idModel = $(this).val();
            $.getJSON("/Statistics/LoadCompetitorsForClub", { id: idModel },
            function (competitorsData) {
                var select = $("#CompetitorId");
                select.empty();
                
                $.each(competitorsData, function (index, itemData) {
                    select.append($('<option/>',
                    {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });
    });
</script> 

